public with sharing class ContractLinkDetailController {
    
    public List<QuoteMeasureProductBean> qmpbList { get; set; }

    public String id { get; private set; }
    public String type { get; private set; }

    public ContractLinkDetailController() {
        qmpbList = new List<QuoteMeasureProductBean>();
        id = System.currentPageReference().getParameters().get('id');
        type = System.currentPageReference().getParameters().get('t');
    }

    public void init() {
        // 报价产品
       if (type == 'q') {
            for (QuoteProduct__c qp : [select Name, Account__r.Name, Brand__c, Category0__c, Category1__c, Category2__c, UnitPrice__c, SalesPrice__c, Quantity__c
                                        from QuoteProduct__c where Quote__c = :id]) {
                qmpbList.add(new QuoteMeasureProductBean(qp));
            }
        }
        // 测算产品
        if (type == 'm') {
            for (Measure_Calculate_Product__c mcp : [select Product__r.Name, Measure_Calculate__r.Opportunity__r.Account.Name, Product__r.Brand__c, 
                                                    Product__r.Category0__c, Product__r.Category1__c, Product__r.Category2__c,
                                                    UnitPriceWT__c, SalesPriceWT__c, TestNum__c
                                                    from Measure_Calculate_Product__c where Measure_Calculate__c = :id]) {
                qmpbList.add(new QuoteMeasureProductBean(mcp));
            }
        }
    }

    public class QuoteMeasureProductBean {
       public String name { get; set; }
        // public productName { get; set; }
        public String accountName { get; set; }
        public String brand { get; set; }
        public String category0 { get; set; }
        public String category1 { get; set; }
        public String category2 { get; set; }
        public Decimal unitPrice { get; set; }
        public Decimal salesPrice { get; set; }
        public Decimal num { get; set; }

        public QuoteMeasureProductBean(QuoteProduct__c record) {
            name = record.Name;
            accountName = record.Account__r.Name;
            brand = record.Brand__c;
            category0 = record.Category0__c;
            category1 = record.Category1__c;
            category2 = record.Category2__c;
            unitPrice = record.UnitPrice__c;
            salesPrice = record.SalesPrice__c;
            num = record.Quantity__c;
        }

        public QuoteMeasureProductBean(Measure_Calculate_Product__c record) {
            name = record.Product__r.Name;
            accountName = record.Measure_Calculate__r.Opportunity__r.Account.Name;
            brand = record.Product__r.Brand__c;
            category0 = record.Product__r.Category0__c;
            category1 = record.Product__r.Category1__c;
            category2 = record.Product__r.Category2__c;
            unitPrice = record.UnitPriceWT__c;
            salesPrice = record.SalesPriceWT__c;
            num = record.TestNum__c;
        }
    }
}